clear;
clf;

file=csvread('/Users/benedictpfender/Google Drive/ME3 - DMT/Test Results/PrincesGardens 20130201/run3.csv',1);
time=file(:,1);
leftraw=file(:,3);
rightraw=file(:,4);

rmsl=rms(leftraw);
rmsr=rms(rightraw);

left=leftraw-rmsl;
right=rightraw-rmsr;


windowSize=100;
avWinSz=500;

yrms=[]; % moving RMS, takes RMS of each sample based on window size
yrms(length(left)-windowSize)=0;
for i=1:(length(left)-windowSize)
    yrms(i)=sqrt(mean(left(i:i+windowSize).^2));
end

yrmsa=[]; % moving average of the RMS data
yrmsa(length(yrms)-avWinSz)=0;
for a=1:avWinSz
    yrmsa=yrmsa+1/avWinSz*yrms(a:(end-avWinSz+a-1));
end

yrms=[]; % moving RMS, takes RMS of each sample based on window size
yrms(length(right)-windowSize)=0;
for i=1:(length(right)-windowSize)
    yrms(i)=sqrt(mean(right(i:i+windowSize).^2));
end

yrmsr=[]; % moving average of the RMS data
yrmsr(length(yrms)-avWinSz)=0;
for a=1:avWinSz
    yrmsr=yrmsr+1/avWinSz*yrms(a:(end-avWinSz+a-1));
end

yrmsa=yrmsa;

plot(left)
hold on
plot(right,'g')
plot(yrmsa,'r')
plot(yrmsr,'k')


%Simple moving averages
forcel=tsmovavg(left,'e',5,1);
forcer=tsmovavg(right,'s',500,1);


%plot(time,left,'b');
%plot(time,forcel,'g');
%plot(time,right,'r');
